package com.cloudeye.benchmark;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.logging.LoggingApplicationListener;
import org.springframework.context.ApplicationListener;

import java.util.Iterator;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@SpringBootApplication
public class BenchmarkApp {

	private static final Logger logger = LoggerFactory.getLogger(BenchmarkApp.class);
	public static void main(String[] args) throws InterruptedException {
//		SpringApplication.run(CloudeyeBenchmarkApplication.class, args);
//		logger.info("this application is running now...");
		SpringApplicationBuilder builder = new SpringApplicationBuilder(BenchmarkApp.class);
		Set<ApplicationListener<?>> listeners = builder.application().getListeners();
		for (Iterator<ApplicationListener<?>> it = listeners.iterator(); it.hasNext();) {
			ApplicationListener<?> listener = it.next();
			if (listener instanceof LoggingApplicationListener) {
				it.remove();
			}
		}
		builder.application().setListeners(listeners);
		builder.run(args);

		logger.info("hi-log-log4j2 start successfully");

		ExecutorService pool = Executors.newFixedThreadPool(100);
		String a = "哈哈";
		int count = 0;
		while (true) {
			pool.execute(new Runnable() {
				@Override
				public void run() {
					logger.info("i am test,UUID：{}", UUID.randomUUID().toString().replaceAll("-",""));
				}
			});
			count++;
			if(count>1){
				Thread.sleep(10000);
				count=0;
			}
		}
	}
}
